package com.hksj.Intelligentmanagement.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hksj.Intelligentmanagement.common.Constants;
import com.hksj.Intelligentmanagement.common.Rest;
import com.hksj.Intelligentmanagement.common.Result;
import com.hksj.Intelligentmanagement.dto.NurseDTO;
import com.hksj.Intelligentmanagement.service.NurseService;
import com.hksj.Intelligentmanagement.vo.NurseVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


@Api(tags = "护士管理")
@RestController
@RequestMapping("/api/nurse")
public class NurseController {

    @Autowired
    private NurseService nurseService;

    @ApiOperation("新增护士")
    @PostMapping("/createNurse")
    public Rest createNurse(@RequestBody @Validated(NurseDTO.Create.class) NurseDTO nurseDTO){
        nurseDTO.setType(Constants.TYPE_NURSE);
        return nurseService.createNurse(nurseDTO);
    }

    @ApiOperation("修改护士")
    @PutMapping("/updateNurse")
    public Rest updateNurse(@RequestBody @Validated(NurseDTO.Update.class) NurseDTO nurseDTO){
        nurseDTO.setType(Constants.TYPE_NURSE);
        return nurseService.updateNurse(nurseDTO);
    }

    @ApiOperation("删除护士")
    @DeleteMapping("/deleteNurse/{id}")
    public Rest deleteNurse(@PathVariable("id") String id){
        return nurseService.deleteNurse(id);
    }

    @ApiOperation("根据护士工号查询护士信息")
    @GetMapping("/queryNurseByEmployeeNumber/{employeeNumber}")
    public Result queryNurseByEmployeeNumber(@PathVariable("employeeNumber") int employeeNumber){
        return nurseService.queryNurseByEmployeeNumber(employeeNumber);
    }

    @ApiOperation("分页动态查询护士列表")
    @PostMapping("/queryNurseListByPage")
    public Result queryNurseListByPage(@RequestBody NurseDTO nurseDTO){
        return Result.ok(nurseService.queryNurseListByPage(nurseDTO));
    }

    //nxfx 查询值班护士
    @ApiOperation("查询当天值班护士列表")
    @PostMapping("/queryNurseListByOperationTime")
    public Result queryNurseListByOperationTime(@RequestBody NurseDTO nurseDTO){
        return Result.data(nurseService.queryNurseListByOperationTime(nurseDTO));
    }

    @ApiOperation("查询所有护士")
    @GetMapping("/listNurse")
    public Rest listNurse(
       @ApiParam(value = "护士姓名",required = false) @RequestParam(required = false) String nurseName){
        return Rest.ok(nurseService.listNurse(nurseName,Constants.TYPE_NURSE));
    }

    @ApiOperation("分页查询护士")
    @GetMapping("/pageNurse")
    public Rest pageNurse(
        @ApiParam(value = "护士姓名",required = false) @RequestParam(required = false) String nurseName,
        @ApiParam(value = "护士工号",required = false) @RequestParam(required = false) String employeeNumber,
        @ApiParam(value = "护士等级id",required = false) @RequestParam(required = false) String nurseLevelId,
        @ApiParam(value = "状态(0:未禁用,1:已禁用)",required = false) @RequestParam(required = false) String status,
        @ApiParam(value = "起始页",required = false,defaultValue = "1") @RequestParam(required = false,defaultValue = "1") Integer pageNum,
        @ApiParam(value = "每页大小",required = false,defaultValue = "10") @RequestParam(required = false,defaultValue = "10") Integer pageSize){
        IPage<NurseVo> pageInfo =  nurseService.pageNurse(new Page<>(pageNum,pageSize),nurseName,employeeNumber,nurseLevelId,status,Constants.TYPE_NURSE);
        return Rest.ok(pageInfo);
    }
}
